package com.baizhi.mall.controller;


import com.baizhi.mall.entity.mysql.BzCategoryDO;
import com.baizhi.mall.service.IBzCategoryService;
import com.baizhi.mall.util.ResultEntity;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品三级分类 前端控制器
 * </p>
 *
 * @author zhw
 * @since 2021-05-17
 */
@RestController
public class BzCategoryController {
    @Autowired
    private IBzCategoryService cs;
    @GetMapping("/categoryTree")
    public ResultEntity<List<BzCategoryDO>> selectTree(){
        List<BzCategoryDO>list =cs.selectTree();
        return ResultEntity.ok();
    }
    @GetMapping("/categoryAll/{parentId}")
    public ResultEntity<List<BzCategoryDO>> selectAll(@PathVariable("parentId") Integer parentId){
        List<BzCategoryDO> list=cs.selectAll(parentId);
        return ResultEntity.ok(list);
    }
    @GetMapping("categoryByPage")
    public ResultEntity<PageInfo<BzCategoryDO>> selectByPage(@RequestParam(defaultValue = "1")Integer pageNum,
                                                         @RequestParam(defaultValue = "5")Integer pageSize){
        PageInfo<BzCategoryDO> info =cs.selectByPage(pageNum, pageSize);
        return ResultEntity.ok(info);
    }
    @DeleteMapping("category/{categoryId}")
    public ResultEntity<String> delete(@PathVariable("categoryId")Integer categoryId){
        cs.delete(categoryId);
        return ResultEntity.ok();
    }
    @GetMapping("/status3")
    public ResultEntity<String> updateStatus(Integer showStatus,Integer categoryId){
        cs.updateStatus(showStatus,categoryId);
        return ResultEntity.ok();
    }
}

